﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Data.Api.Repositories;
using Data.Api.Db;
using Entity.Baskets;

namespace Shop.Managers
{
    public class ManagerBasket : IManagerBasket
    {
        private IBasketRepository repository;
        private IShopContext context;

        public ManagerBasket(IBasketRepository repository, IShopContext context)
        {
            this.repository = repository;
            this.context = context;
        }

        public void AddNewProduct(Entity.Products.Product product, string username)
        {
            repository.AddNewOrder(product, username);
            context.Commit();
        }

        public IQueryable<Entity.Baskets.Basket> GetAllOrdersForUser(string username, State state)
        {
            return repository.GetAllOrdersForUser(username, state);
        }

        public void DeleteOrderPosition(int IdOrderPosition)
        {
            repository.DeleteOrderPosition(IdOrderPosition);
            context.Commit();
        }

        public void SubmitOrder(string username)
        {
            repository.SubmitOrder(username);
            context.Commit();
        }


        public IQueryable<Basket> GetAllOrders(State state)
        {
            return repository.GetAllOrders(state);
        }

        public void DeleteBasket(int IdBasket)
        {
            repository.DeleteBasket(IdBasket);
            context.Commit();
        }

        public decimal GetPrice(string username)
        {
            return repository.GetPrice(username);
        }
    }
}